function ShowContextMenu(e,id){
    e.returnValue = false;
	var div = document.getElementById(id);
	div.style.display = 'block';
	var left = parseInt(e.clientX);
	var height = parseInt(e.clientY);
	var divX = parseInt(div.clientWidth, 10);
	var divY = parseInt(div.clientHeight, 10);
	var bodyX = parseInt(document.body.clientWidth, 10);
	var bodyY = parseInt(document.body.clientHeight, 10);
	var newW = 0;
	var newHeight = 0;

	if(left > (bodyX*9/10)){

		newW = left - divX ;
	}else{

		newW = left;
	}

	if(bodyY-height < divY+20){
       if(height<divY+20){

	   	 if(height<50){
           newHeight = height;
		 }else {
		 	 newHeight=divY/2-20;
		 }


	   } else {

			newHeight=height-divY;
	   }

	}else{

		newHeight = height;
	}



	div.style.left = newW;
	div.style.top = newHeight;



	document.body.onclick = function(){
		HideContextMenu(id);
	};
	//event.cancelBubble = true
	return false;
}
function HideContextMenu(ID){
	document.getElementById(ID).style.display="none";
	document.body.onclick = null;
}

function ShowContextNav(id,e,butonId){

	var thistop=e.offsetTop;
	var thisleft=e.offsetLeft;
	while(e=e.offsetParent)
	{
		thistop+=e.offsetTop;
		thisleft+=e.offsetLeft;
	}
	var dgetID=document.getElementById(id);
	dgetID.style.left=20;
	dgetID.style.top=thistop+20;
	dgetID.style.display="block";


	document.body.onclick = function(){
		HideContextNav(id,butonId);
	};

	return false;
}
function HideContextNav(ID,butonId){
	document.getElementById(ID).style.display="none";
	document.body.onclick = null;
	var new_td21b="btn1_"+butonId+"2";
	eval("document.all."+new_td21b).onclick();
}
